﻿Public Class DBADO_NET
    Private state As Integer '0 mac dinh , 1 tao moi , 2 sua

    Private Sub DBADO_NET_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.BacsiTableAdapter.Fill(Me.PcvgppDataSet.bacsi)
        Me.ButtonLuu.Enabled = False
        Me.ButtonXoa.Enabled = False
        Me.state = 0 'mac dinh
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles ButtonTaoMoi.Click
        Me.BacsiBindingSource.AddNew()
        state = 1 'tao moi
    End Sub

    Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
        Me.BacsiBindingSource.MoveFirst()
    End Sub

    Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
        Me.BacsiBindingSource.MovePrevious()
    End Sub

    Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
        Me.BacsiBindingSource.MoveNext()
    End Sub

    Private Sub Button9_Click(sender As System.Object, e As System.EventArgs) Handles Button9.Click
        Me.BacsiBindingSource.MoveLast()
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles ButtonLuu.Click
        'kiem tra du lieu
        '1 co thay doi
        Me.BacsiBindingSource.EndEdit()
        If Me.PcvgppDataSet.HasChanges Then
            MessageBox.Show("co thay doi du lieu !")
            Me.BacsiTableAdapter.Update(Me.PcvgppDataSet.bacsi)
            state = 0
        Else
            MessageBox.Show("khong thay doi du lieu !")
            state = 0
        End If
        '2 khong thay doi
    End Sub

    Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles ButtonXoa.Click
        Me.BacsiBindingSource.RemoveCurrent()
        Me.BacsiTableAdapter.Update(Me.PcvgppDataSet.bacsi)
    End Sub

    Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles ButtonHuyThayDoi.Click
        Me.BacsiBindingSource.EndEdit()
        Me.PcvgppDataSet.RejectChanges()
    End Sub

    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles ButtonSua.Click
        Me.ButtonLuu.Enabled = True
        Me.ButtonXoa.Enabled = True
        Me.ButtonSua.Enabled = False
        state = 2
    End Sub
End Class